<script>
import CardItems from '@/components/CardItems/index.vue'
import { cardConfig } from './config/cardConfig'
import { popConfig } from './config/popConfig'
import { headerConfig } from './config/tableConfig'
import { selectConfig } from './config/selectConfig'
import { parseSceneData } from '@/utils/scene-data'

export default {
  name: 'RunningModeData',
  components: { CardItems },
  computed: {
    /**
     * 卡片配置
     */
    cardConfig() {
      return cardConfig['runningModeData'] || {}
    },
    /**
     * 弹窗配置
     */
    popConfig() {
      return popConfig['runningModeData'] || {}
    },
    /**
     * 筛选配置
     */
    selectConfig() {
      return this.selectList || []
    },
    /**
     * 表头配置
     */
    headerConfig() {
      return headerConfig['runningModeData'] || []
    }
  },
  data() {
    return {
      selectList: selectConfig['runningModeData']
    }
  },
  methods: {
    selectChange(selectData, prop, selectList) {
      this.selectList = JSON.parse(JSON.stringify(selectList))
      if (prop === 'sceneProjectId') {
        this.getRoomList(selectData[prop], selectList, selectData)
      }
      if (prop === 'sceneInfo') {
        const infos = selectData[prop]
        selectData.sceneEdificeId = infos[0] || undefined
        selectData.sceneFloorId = infos[1] || undefined
        selectData.sceneRoomId = infos[2] || undefined
      }
    },
    async getRoomList(sceneProjectId, selectList, selectData) {
      let roomList = []
      if (sceneProjectId != null && sceneProjectId !== '') {
        const res = await this.$api.sceneRoom.queryRoomList({
          sceneProjectId,
          sortColumn: 'floorName',
          sortOrder: 'asc'
        })
        roomList = parseSceneData(res.data)
      }
      const configItem = selectList[3]
      configItem.optionList = roomList
      this.$set(this.selectList, 3, {
        ...configItem
      })
      this.$refs.cardItemsRef.setSelectModuleValue({
        ...selectData
      })
    }

  }
}
</script>

<template>
  <div class="running-mode-box">
    <div class="CardItems-box">
      <CardItems
        ref="cardItemsRef"
        :card-config="cardConfig"
        :pop-config="popConfig"
        :select-config="selectConfig"
        :header-config="headerConfig"
        @selectChange="selectChange"
      />
    </div>
  </div>
</template>
<style lang="scss" scoped>
.running-mode-box {
  display: flex;
  width: 100%;
  height: 100%;

  .expand-box {
    position: absolute;
    top: 50%;
    height: 40px;
    line-height: 40px;
    width: 12px;
    text-align: center;
    margin-top: -20px;
    font-size: 12px;
    color: #909399;
    background-color: #ededed;
    border-radius: 0 4px 4px 0;
    transition: left 0.3s;
    cursor: pointer;
    z-index: 3;

    &:hover {
      background-color: #ddd;
    }

    .el-input__icon {
      font-style: normal;
      font-weight: 400;
      font-variant: normal;
      text-transform: none;
      line-height: 1;
      vertical-align: baseline;
      display: inline-block;
    }
  }

  .TreeCard-box {
    height: 100%;
    transition: all 0.3s;

    .tree-card {
      border: 1px solid #eee;
      background-color: #fff;
    }

    &.is-expand {
      overflow: hidden;
      margin-right: 0;
    }
  }

  .CardItems-box {
    flex: 1;
  }
}
</style>
